package com.zwface.demo.function.leave.adapter;

import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zwface.demo.R;
import com.zwface.demo.comm.comm;
import com.zwface.demo.model.db.Leave;

import androidx.annotation.NonNull;


/**
 * created by 张中文
 * on 2020/5/2
 * 描述：
 */
public class LeaveLsAdapter extends BaseQuickAdapter<Leave, BaseViewHolder>
{
    private Boolean isTeacher;
    public LeaveLsAdapter() {
        super(R.layout.item_leave_ls,null);
    }

    public void isTeacher(Boolean isTeacher){
        this.isTeacher = isTeacher;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, Leave item) {
        String timeS = TimeUtils.millis2String(item.getTimeStart(),"MM-dd HH:mm");
        String timeE = TimeUtils.millis2String(item.getTimeEnd(),"MM-dd HH:mm");
        helper.setText(R.id.tv_time,timeS+"-"+timeE);
        helper.setText(R.id.tv_name,item.getStuName());
        helper.setText(R.id.tv_reason,"原因："+item.getReason());
        TextView tvStatus = helper.getView(R.id.tv_status);
        LinearLayout llBtns = helper.getView(R.id.ll_btns);
        String status = "";
        int statusColor = 0;
        switch (item.getStatus()){
            case comm.LEAVE_STATUS_WAITING:
                status = "等待审核";
                statusColor = ColorUtils.getColor(R.color.gray_9);
                if(isTeacher)
                    llBtns.setVisibility(View.VISIBLE);
                break;
            case comm.LEAVE_STATUS_PASS:
                status = "已批准";
                statusColor = ColorUtils.getColor(R.color.theme);
                break;
            case comm.LEAVE_STATUS_REFUSE:
                status = "未通过";
                statusColor = Color.RED;
                break;
        }
        tvStatus.setText(status);
        tvStatus.setTextColor(statusColor);
        helper.addOnClickListener(R.id.btn_pass);
        helper.addOnClickListener(R.id.btn_refuse);
    }
}
